import math


class Solution(object):
    def findContestMatch(self, n):
        """
        :type n: int
        :rtype: str
        """
        out = [[i + 1] for i in range(n)]
        m = n
        while m > 1:
            next_list = []
            index = 0
            while index < m // 2:
                next_list.append(out[index] + out[m - 1 - index])
                index += 1
            out = next_list
            m = m // 2
        out = out[0]
        k = math.log2(n)
        self.index = 0

        def search(t):
            if t < k:
                left = search(t + 1)
                right = search(t + 1)
                return '(' + left + ',' + right + ')'
            else:
                val = str(out[self.index])
                self.index += 1
                return val

        return search(0)


data = Solution()
n = 4
print(data.findContestMatch(n))
